import java.util.Set;
import java.util.TreeSet;

public class Test740 {
    public static void main(String[] args) {
        Test740 test740 = new Test740();
        int[] nums = {3,4,2};
        System.out.println(test740.deleteAndEarn(nums));
    }

    public int deleteAndEarn(int[] nums) {
        Set<Integer> treeSet = new TreeSet<>();
        for (int num : nums) {
            treeSet.add(num);
        }
        Integer[] array = treeSet.toArray(new Integer[]{});
        int max = array[array.length-1];
        int i = array.length-2;
        while (i>0&&array[i]*3>max){
            if(array[i]+1==array[i+1]&&array[i]-1==array[i-1]){
                return array[i]*3;
            }else if(array[i]+1==array[i+1]){
                max = Math.max(array[i]+array[i+1],max);
            }
        }
        return max;
    }


}
